package com.cloud.punish.interfaces;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.cloud.punish.common.config.FeignConfiguration;
import com.cloud.punish.common.result.QkTreeNode;

import feign.hystrix.FallbackFactory;

@FeignClient(value = "FORM", configuration = FeignConfiguration.class, fallbackFactory = FeignClientFormFallbackFactory.class)
public interface FeignClientForm {

	/**
	 * 获取参与者在指定环节的案卷权限信息
	 * 
	 * @param recId
	 * @param actDefId
	 * @param parts
	 * @return
	 */
	@RequestMapping(value = "form/api/interface/listformtree", method = RequestMethod.POST)
	QkTreeNode[] listFormTree(@RequestParam("recId") long recId, @RequestParam("actDefId") Long actDefId,
			@RequestParam("parts") String parts);

	/**
	 * 获取参与者在指定环节的案卷权限信息
	 * 
	 * @param recId
	 * @param actDefId
	 * @param parts
	 * @return
	 */
	@RequestMapping(value = "form/api/interface/listprintformtree", method = RequestMethod.POST)
	QkTreeNode[] listPrintFormTree(@RequestParam("recId") long recId, @RequestParam("actDefId") Long actDefId,
			@RequestParam("parts") String parts);

}

@Component
class FeignClientFormFallbackFactory implements FallbackFactory<FeignClientForm> {
	private static final Logger LOGGER = LoggerFactory.getLogger(FeignClientFormFallbackFactory.class);

	@Override
	public FeignClientForm create(Throwable cause) {
		return new FeignClientForm() {

			@Override
			public QkTreeNode[] listFormTree(long recId, Long actDefId, String parts) {
				if (FeignClientFormFallbackFactory.LOGGER.isDebugEnabled()) {
					FeignClientFormFallbackFactory.LOGGER.debug("listFormTree fallback; reason was:" + cause);
				}
				return null;
			}

			@Override
			public QkTreeNode[] listPrintFormTree(long recId, Long actDefId, String parts) {
				if (FeignClientFormFallbackFactory.LOGGER.isDebugEnabled()) {
					FeignClientFormFallbackFactory.LOGGER.debug("listPrintFormTree fallback; reason was:" + cause);
				}
				return null;
			}
		};

	}

}